package com.jzr.task.job.kangying;

import com.jzr.task.db1.service.KangYingService;
import com.jzr.task.db1.vo.KySeatBedVo;
import com.jzr.task.job.BaseJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Component("KangYing.SyncSeatBed")
public class KySyncSeatBed extends BaseJob {
    @Value("${kangying.apiUrl}")
    private String apiUrl;

    @Autowired
    private KangYingService kangYingService;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public void process() throws Exception {
        //同步SeatBed
        List<KySeatBedVo> list = kangYingService.getSeatBedList(null);
        if(list != null && list.size()>0) {
            KyResult result = KyRestTemplateUtil.postJson(restTemplate, apiUrl + "SeatBed/SeatListSync", list, KyResult.class);
            if (result == null) {
                throw new Exception("同步康英SeatBed时无法获取返回结果");
            }
            if (result.getStatus() == -1) {
                throw new Exception("同步康英SeatBed失败," + result.getMessage() + "," + result.getContent());
            }
        }
    }
}
